<template>
  <div class="goods-hot">
    <h3>{{types[type]}}</h3>
    <!-- 商品区块 -->
    <home-good v-for="(good,index) in data" :good="good" :key="index"/>
  </div>
</template>

<script>
import HomeGood from '@/views/home/components/home-goods'
import { findHotGoods } from '@/api/good'
import { useRoute } from 'vue-router'
import { onMounted, ref } from 'vue'
export default {
  props: {
    // type作为一个判断条件用来渲染不同的title 和调用接口时传入不同的字段值
    // 1 小时 2 周 3 总
    type: {
      type: String
    }
  },
  setup (props) {
    const types = {
      1: '24小时热榜',
      2: '周热榜',
      3: '总热榜'
    }
    const route = useRoute()
    const data = ref([])
    async function loadData () {
      const res = await findHotGoods({ id: route.params.id, type: props.type })
      data.value = res.result
      console.log(res)
    }
    onMounted(() => {
      loadData()
    })
    return {
      types,
      data
    }
  },
  components: {
    HomeGood
  }
}
</script>

<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
